
mini.parse();
var grid = mini.get("datagrid1");
var tree = mini.get("tree1");
tree.setUrl(ajaxUrl + "/TreeController/MoMeList.do");
//赋值
function SetData(data) {
    if (data.action == "treeMoMe") {
        //跨页面传递的数据对象，克隆后才可以安全使用
        data = mini.clone(data);
        var reportId = data.reportId;
        mini.getByName("reportId").setValue(reportId);
        $.ajax({
            url: ajaxUrl + "/TreeController/MoMeList.do",
            type : "POST",
            success: function (data) {
            	console.log("返回值");
            	console.log(data);
            	tree.setData(data.treeDate);
            	console.log(tree);
            },
            error:function(data){
                mini.alert('失败');
            }
        });
    }
}

function RelationMenu(){
	var selectNode = tree.getSelectedNode();
	var parNodeObj = {};
	var menuId = selectNode.pk;
	var reportId = mini.getByName("reportId").getValue();
	console.log(typeof selectNode.reportId)
	if(selectNode.id.substring(0,2) == "mo"){
		mini.alert("不可将将报表绑定在模块位置，请重新选择！！");
	}else if(selectNode.reportId != 0){
		mini.alert("该模块已有绑定报表，请重新选择！！");
	}else if(selectNode.url){
		mini.alert("当前菜单存在跳转路径，请先前往菜单模块清空后，再做关联操作");
	}else{
		if(selectNode.children != ""){
			mini.alert("当前节点存在下级菜单，不允许关联，请重新选择！！");
		}else{
		$.ajax({
			url:ajaxUrl + "/reportController/RelationMenu.do?menuId="+menuId+"&reportId="+reportId,
			type:"POST",
			success: function(data){
				mini.alert("关联成功")
				 $.ajax({
			            url: ajaxUrl + "/TreeController/MoMeList.do",
			            type : "POST",
			            success: function (data) {
			            	tree.setData(data.treeDate);
			            	console.log(tree);
			            },
			            error:function(data){
			                mini.alert('失败');
			            }
			        });
			},
			error: function(data){
				mini.alert("关联失败");
				 $.ajax({
			            url: ajaxUrl + "/TreeController/MoMeList.do",
			            type : "POST",
			            success: function (data) {
			            	tree.setData(data.treeDate);
			            	console.log(tree);
			            },
			            error:function(data){
			                mini.alert('失败');
			            }
			        });
			}
		})
		}
	}
}

function deleteRelation(){
	var selectNode = tree.getSelectedNode();
	var parNodeObj = {};
	var menuId = selectNode.pk;
	console.log(typeof selectNode.reportId)
	if(selectNode.id.substring(0,2) == "mo"){
		mini.alert("您点选的是模块，请重新选择！！");
	}else if(selectNode.reportId != 0){
		mini.confirm("确定取消关联吗？","系统提示",function(action){
			if(action == "ok"){
				$.ajax({
					url:ajaxUrl + "/reportController/deleteRelation.do?menuId="+menuId,
					type:"POST",
					success: function(data){
						mini.alert("取消关联成功");
						 $.ajax({
					            url: ajaxUrl + "/TreeController/MoMeList.do",
					            type : "POST",
					            success: function (data) {
					            	tree.setData(data.treeDate);
					            	console.log(tree);
					            },
					            error:function(data){
					                mini.alert('失败');
					            }
					        });
					},
					error: function(data){
						mini.alert("取消关联失败");
						 $.ajax({
					            url: ajaxUrl + "/TreeController/MoMeList.do",
					            type : "POST",
					            success: function (data) {
					            	tree.setData(data.treeDate);
					            	console.log(tree);
					            },
					            error:function(data){
					                mini.alert('失败');
					            }
					        });
					}
				})
			}
		})
	}
}


//点击树节点的时候
tree.on("nodeselect", function (e) {
    //被选中得节点
    var selecNode = e.node;
    mini.getByName("select").setValue(selecNode.text);
    
});